# -*- coding:utf-8 -*-
import os

from PIL import Image

import html_url


def joint(image_list, picture_name=None):
    if not picture_name:
        picture_name = os.path.split(image_list[0])[1].replace('_1.gif', '.jpg')
    images = [Image.open(fn).convert('RGB') for fn in image_list]
    width, _ = images[0].size
    height = 0
    for image in images:
        height += image.size[1]
    print(height)
    result = Image.new(images[0].mode, (width, height))
    where = 0
    for i, image in enumerate(images):
        result.paste(image, box=(0, where))
        where += image.size[1]
        print(width, where)
    result.save(picture_name)


if __name__ == '__main__':
    # html_downloader.download_pic("2.jpg", "http://cdn.daweijita.com/2015/09/tab_asi_wzrmgcczj_2.gif")
    # html_downloader.split(['1.gif','2.gif'])
    # html_downloader.download_vip_pic('五月天', 'http://cdn.daweijita.com/2018/05/fufei_wuyuetian_houlaidewomen.gif')
    # http://www.ccguitar.cn/pu/2018/5/24/125059_2256/1.jpg
    # picture_list = [r'dist\tab_asi_wzrmgcczj_1.gif', r'dist\tab_asi_wzrmgcczj_2.gif']
    # joint(picture_list)
    html_url.HtmlUrl().write_urls(
        ['http://www.daweijita.com/667.html/comment-page-64', 'http://www.daweijita.com/667.html/comment-page-64'],'old_url.txt')
    print(html_url.HtmlUrl().get_urls('old_url.txt'),)
    pass
